#include<stdlib.h>
#include<string.h>

void select_sort(void *arr, int num, int size, int (*cmp)(const void*num1, const void*num2)){
	int min;
	int i, j;
	void *t = malloc(size);
	for(i = 0; i < num - 1; i++){
		min = i;
		for(j = i + 1; j < num; j++){
			if(cmp((char *)arr + min * size, (char *)arr + j * size) > 0){
				min = j;
			}
		}
		if(min != i){
			memcpy(t, (char *)arr + i * size, size);
			memcpy((char *)arr + i * size, (char *)arr + min * size, size);
			memcpy((char *)arr + min * size, t, size);
		}
	}
	free(t);
	t = NULL;	
}

void show_arr(void *arr, int num, int size, void (*pri)(const void*p)){
	int i;
	for(i = 0; i < num; i++){
		pri((char *)arr + i * size);
	}

}
